package com.im.domain;

import javax.websocket.Session;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * websocket 信息对象
 * 用户存储socket链接信息
 */
public class WebSocketBean {

    /**
     * 链接session对象
     */
    private Session session;

    /**
     * 链接错误的次数
     */
    private AtomicInteger errorLinkCount = new AtomicInteger(0);

    public int getErrorLinkCount(){
        // 线程安全，以原子方式将当前值加1，注意：这里放回的是自增的值
        return errorLinkCount.getAndIncrement();
    }

    public void cleanErrorNum(){
        errorLinkCount = new AtomicInteger(0);
    }

    public Session getSession() {
        return session;
    }

    public void setSession(Session session) {
        this.session = session;
    }

    public void setErrorLinkCount(AtomicInteger errorLinkCount) {
        this.errorLinkCount = errorLinkCount;
    }
}
